package com.bzgwl.mybatis_plus.exception;


import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class GlobalDefaultExceptionHandler implements HandlerExceptionResolver {

    /**
     * 如果均返回同一个ModelAndView显然可能有点不合适，对于ajax可能需要特别处理。
     * 但是 Spring 官方不推荐使用它。
     * @param httpServletRequest
     * @param httpServletResponse
     * @param o
     * @param e
     * @return
     */
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        if (e instanceof UnauthorizedException) {
            ModelAndView mv = new ModelAndView("/403");
            return mv;
        }
        return null;
    }
}
